﻿package {
	import flash.events.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class Configuration extends EventDispatcher{
		private var _cfgPath:String;
		private var _refreshRate:int;
		private var XMLData:XMLList;
		private var _XmlHndler:XML;
		private var _cfg:Object;
		private var isReady:Boolean = false;
		
		public function Configuration(path:String)
		{
			trace("Configuration creating");
			_cfgPath = path;
			loadXmlContent();
		}
		
		private function loadXmlContent():void{
			var xmlLdr:URLLoader = new URLLoader();
			xmlLdr.addEventListener(Event.COMPLETE, completeHandler);
			xmlLdr.load(new URLRequest(_cfgPath));//"men_imgs.xml"));
			trace("[Configuration]Start load of xml config");
		}
		
		public function completeHandler(event:Event):void {
			trace("[Configuration]completeHandler");
			try {
				trace(event.target.data);
				this._XmlHndler = new XML(event.target.data);
				XML.ignoreWhitespace = true; 
				isReady = true;
				
				trace(_XmlHndler);
				_refreshRate = _XmlHndler.refresh_rate.text();
				
				
				trace(_XmlHndler.webdir.text());

				
			} catch (error:Error) {
				trace(error.message);
			}
			dispatchEvent(new Event("CONFLOADED"));
		}
		
		public function get title():String{
			return this._XmlHndler.title;
		}
		public function get host():String{
			return this._XmlHndler.host;
		}
		public function get dbhost():String{
			return this._XmlHndler.dbhost;
		}
		public function get webdir():String{
			return this._XmlHndler.webdir;
		}
	}
}